<template>
  <div class="noticeInfo">
    <mu-appbar :z-depth="0" style="width: 100%;top: 0" color="white" text-color="primary">
      <mu-button icon slot="left">
        <header-back></header-back>
      </mu-button>
      公告详情
      <mu-button icon slot="right" @click="goCase">
        <mu-icon value="chrome_reader_mode"></mu-icon>
      </mu-button>
    </mu-appbar>
    <div class="content">
      <div>
        <mu-paper class="paper" :z-depth="0">
          <mu-list dense style="height: 100%;padding: 0 1rem 0 1rem">
            <h4>公告信息</h4>
            <mu-divider></mu-divider>
            <mu-list-item class="list-item" button ripple>
              <mu-list-item-title class="item-title">标题：</mu-list-item-title>
              <mu-list-item-content class="item-content">
                <h4>
                  {{notice.title}}</h4>
              </mu-list-item-content>
              <mu-list-item-action>
              </mu-list-item-action>
            </mu-list-item>
            <mu-list-item class="list-item" button ripple>
              <mu-list-item-title class="item-title">类型：</mu-list-item-title>
              <mu-list-item-content class="item-content">
                {{fhConstant ? fhConstant.title :''}}
              </mu-list-item-content>
              <mu-list-item-action>
              </mu-list-item-action>
            </mu-list-item>
            <mu-list-item class="list-item" button ripple>
              <mu-list-item-title class="item-title">时间：</mu-list-item-title>
              <mu-list-item-content class="item-content">
                {{util.formatyyyyMMddDate(notice.releaseTime)}}
              </mu-list-item-content>
              <mu-list-item-action>
              </mu-list-item-action>
            </mu-list-item>
          </mu-list>
        </mu-paper>
        <mu-paper class="paper" :z-depth="0">
          <mu-list style="padding: 0 1rem 0 1rem">
            <h4>公告正文</h4>
            <mu-divider></mu-divider>
            <mu-container class="demo-text">
              <span v-html="notice.context ? notice.context : '暂无'"></span>
            </mu-container>
          </mu-list>
        </mu-paper>
        <mu-paper round class="paper" :z-depth="0">
          <mu-list style="padding: 0 1rem 0 1rem">
            <h4>公告文件</h4>
            <mu-divider></mu-divider>
            <mu-expansion-panel :zDepth=depth class="grid-cell" v-for="(item,index) in files" v-bind:key="item.id"
                                :expand="panel === index" @change="toggle(index)">
              <div slot="header">{{item.name}}</div>
              <div style="width: 120%" v-if="item.type === 'pdf'">
                <pdf :url="item.url"></pdf>
              </div>
              <div v-else class="pic">
                <img :src="item.url" style="width: 100%;">
              </div>
            </mu-expansion-panel>
          </mu-list>
        </mu-paper>
        <mu-paper round class="paper" :z-depth="0">
          <mu-list style="padding: 0 1rem 0 1rem">
            <h4>公告附件</h4>
            <mu-divider></mu-divider>
            <mu-expansion-panel :zDepth=depth class="grid-cell" v-for="(item,index) in enclosureFiles"
                                v-bind:key="item.id"
                                :expand="panel === index" @change="toggle(index)">
              <div slot="header">{{item.name}}</div>
              <div style="width: 120%" v-if="item.type === 'pdf'">
                <pdf :url="item.url"></pdf>
              </div>
              <div v-else class="pic">
                <img :src="item.url" style="width: 100%;">
              </div>
            </mu-expansion-panel>
          </mu-list>
        </mu-paper>
      </div>
    </div>
  </div>
</template>

<script>
  import headerBack from '@/components/headerBack';
  import pdf from '@/components/pdf.vue';

  export default {
    name: 'declareInfo',
    data() {
      return {
        caseRNotice: {},
        notice: {},
        fhConstant: {
          title: ''
        },
        files: [],
        enclosureFiles: [],
        openAlert: false,
        open: false,
        depth: 0,
        panel: '',
        active: 0
      }
    },
    methods: {
      goCase() {
        if (this.caseRNotice && this.caseRNotice.caseId) {
          this.$router.push({name: 'caseInfo', query: {id: this.caseRNotice.caseId}});
        } else {
          this.$toast.info("该公告无案件关联,无法进入案件详情")
        }
      },
      closeAlertDialog() {
        this.openAlert = false;
      },
      closeBottomSheet() {
        this.open = false;
      },
      getData() {
        const _self = this;
        let params = {
          id: this.$route.query.id
        };
        this.postRequest("/openNotice/info", params).then(res => {
          if (res.code === 200) {
            _self.notice = res.data.notice;
            _self.fhConstant = res.data.fhConstant;
            _self.files = res.data.files;
            _self.enclosureFiles = res.data.enclosureFiles;
            _self.caseRNotice = res.data.caseRNotice;
          }
        });
      },
      toggle(panel) {
        this.panel = panel === this.panel ? '' : panel;
      },
      join() {
        let token = this.getStore("accessToken");
        if (!token) {
          this.open = true;
        } else {
          this.openAlert = true;
        }
      },
      openUrl(url) {
        window.open(url);
      }
    },
    mounted() {
      this.getData();
    },
    components: {
      pdf,
      headerBack
    }
  }
</script>

<style scoped lang="scss">
  .noticeInfo {
    position: fixed;
    top: 0;
    width: 100%;
    overflow: hidden;
    height: 100%;
    background-color: #f9f9f9;
    z-index: 9999;
  }

  .content {
    height: 92%;
    overflow: scroll;
  }

  .pic {
    width: 100%;
    display: inline-block;
    vertical-align: middle;
    text-align: center;
  }

  .grid-cell {
    /*margin-top: 10px;*/
    border-radius: 6px;
  }

  .paper {
    margin-top: 10px;
  }

  .demo-text {
    padding: 10px;
    span {
      margin: 1rem;
    }
  }

  .item-title {
    width: 20%;
  }

  .item-content {
    width: 85%;
    font-size: 14px;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .item-action {
    width: 30px;
  }
</style>
